package com.study.mirrorforest.main.common.exception;

import com.study.mirrorforest.main.common.response.R;
import org.apache.ibatis.binding.BindingException;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
public class GlobalExceptionHandler {

    @ExceptionHandler(BindingException.class)
    public R<?> handleBindingException(BindingException ex) {
        return R.error(HttpStatus.INTERNAL_SERVER_ERROR.value(), "MyBatis 配置错误: " + ex.getMessage());
    }

    @ExceptionHandler(Exception.class)
    public R<?> handleException(Exception ex) {
        return R.error(HttpStatus.INTERNAL_SERVER_ERROR.value(), ex.getMessage());
    }
}

